# coding:utf-8
"""
Author: r.xw
Date: 2024/1/1
File: article.py
"""
from sqlalchemy import Table
from common.database import db_connect
from app.config.config import config
from app.settings import env

db_session, base, engine = db_connect()


class Article(base):
    __table__ = Table("article", base.metadata, autoload_with=engine)

    def get_one(self):
        return db_session.query(Article).first()

    def get_list(self, page):
        page = 1 if page is None or int(page) < 1 else int(page)
        count = int(page) * config[env].page_count
        articles = db_session.query(Article).order_by(Article.article_id.desc()).limit(count).all()
        return articles
